/**
 * Created by xuhenian on 2016/8/31.
 */


let $ = require('jquery');

let plug_name = 'plugsName', plug_version = '0.1.0',
  defaults_config = {};

class jQPlug {

  /**
   * 构造函数
   * @param el
   * @param options
   */
  constructor(el, options) {
    this.plugName = plug_name;
    this.version = plug_version;
    this.defaults = defaults_config;
    this.$context = $(el);
    //深度合并参数
    this.config = $.extend(true, {}, this.defaults, options);
    //在元素上存放此实例对象,以 zte + 插件名称为键名
    $.data(el, 'zte_' + plug_name, this);
  }

  /**
   * 初始化元素
   */
  initElements() {
  }

  /**
   * 初始化事件绑定
   */
  initEvent() {
  }

  setConfig(options) {
    this.config = $.extend(true, {}, this.defaults, options);
  }
}

$[plug_name] = jQPlug;
$.fn[plug_name] = function (options) {
  options = options || {};
  if (typeof options === 'object') {
    return this.each(function () {
      var $plug = $(this).data('zte_' + plug_name);
      if ($plug === undefined) {
        new jQPlug(this, options);//创建插件
      } else {
        $plug.setConfig(options);//设置参数
      }
    })
  } else {
    //在此定义更多参数类型
  }
};

module.exports = function (el, options) {
  return $(el)[plug_name](options);
};


